#ifndef MYWORD_H
#define MYWORD_H

#include <QMainWindow>
#include <QMdiArea>
#include <QAction>
#include <QMenu>
#include <QComboBox>
#include <QFontComboBox>
#include <QMdiSubWindow>
#include <QSignalMapper>
#include <QPrinter>
#include "mychild.h"

class MyWord : public QMainWindow
{
    Q_OBJECT

public:
    MyWord(QWidget *parent = nullptr);
    ~MyWord();

private:
    QMdiArea *mdiArea;
    QSignalMapper *windowMapper;    //信号映射器

    //菜单
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *formatMenu;
    QMenu *fontMenu;
    QMenu *alignMenu;
    QMenu *windowMenu;
    QMenu *helpMenu;

    //动作(Action)
    QAction *newAct;    //"文件"主菜单
    QAction *openAct;
    QAction *saveAct;
    QAction *saveAsAct;
    QAction *printAct;
    QAction *printPreviewAct;
    QAction *exitAct;

    QAction *undoAct;   //"编辑"主菜单
    QAction *redoAct;
    QAction *cutAct;
    QAction *copyAct;
    QAction *pasteAct;

    QAction *boldAct;   //"格式"主菜单
    QAction *italicAct;
    QAction *underlineAct;
    QAction *leftAlignAct;
    QAction *centerAct;
    QAction *rightAlignAct;
    QAction *justifyAct;
    QAction *colorAct;

    QAction *closeAct;  //"窗口"主菜单
    QAction *closeAllAct;
    QAction *tileAct;
    QAction *cascadeAct;
    QAction *nextAct;
    QAction *previousAct;
    QAction *separatorAct;

    QAction *aboutAct;  //"帮助"主菜单
    QAction *aboutQtAct;

private:
    QToolBar *fileToolBar;  //"文件"工具条
    QToolBar *editToolBar;  //"编辑"工具条
    QToolBar *formatToolBar;//"格式"工具条
    QToolBar *comboToolBar; //组合选择栏
    QComboBox *comboStyle;   //标号与编号选择框
    QFontComboBox *comboFont; //字体选择框
    QComboBox *comboSize;   //字号选择框

protected:
    void closeEvent(QCloseEvent *event);

private:
    void createActions();
    void createMenus();
    void createToolBars();
    void createStatusBar();
    void enabledText();
    MyChild *activeMyChild();   //活动窗口
    QMdiSubWindow *findMyChild(const QString &fileName);    //查找子窗口

private slots:
    void textAlign(QAction *a);
    void updateMenus();    //更新菜单
    void updateWindowMenu();
    void about();
    void fileNew(); //新建文件操作
    void fileOpen(); //打开文件操作
    void fileSave(); //文件保存操作
    void fileSaveAs(); //文件另存为操作
    void undo();
    void redo();
    void cut();
    void copy();
    void paste();
    void textBold();
    void textItalic();
    void textUnderline();
    void textFamily(const QString &f);
    void textSize(int p);
    void textColor();
    void textStyle(int styleIndex);
    void filePrint();
    void filePrintPreview();
    void printPreview(QPrinter *);
    MyChild *createMyChild();   //创建子窗体
    //void setActiveSubWindow(QObject *object);
};
#endif // MYWORD_H
